/**
 * @param {string[]} emails
 * @return {number}
 */
function isSameDomain(a, b) {
    return a === b
}

function cleanLocalName(name) {
    // + 后直接删除
    // 剔除 .
    let _a = name.replace(/\./g, '')
    let _aParts = _a.split('+')
    _a = _aParts[0]
    return _a
}

// 名字中的 . 可以忽略不计
// 名字中的 + 后面的部分忽略不计
function isSameLocalName(a, b) {
    let _a = cleanLocalName(a)
    let _b = cleanLocalName(b)
    return _a === _b
}

function isSameMail(a, b) {
    let aParts = a.split('@')
    let bParts = b.split('@')
    return isSameLocalName(aParts[0], bParts[0]) && isSameDomain(aParts[1], bParts[1])
}

let numUniqueEmails = function (emails) {
    let distinctEmails = [];

    emails.forEach(mail => {
        if (distinctEmails.length === 0) {
            distinctEmails.push(mail)
        } else {
            let alreadyIn = false;
            distinctEmails.forEach(distEmail => {
                if (isSameMail(mail, distEmail)) {
                    alreadyIn = true
                    return false
                }
            });
            if (!alreadyIn) {
                distinctEmails.push(mail)
            }
        }
    });

    return distinctEmails.length
};

let data = [
        "fg.r.u.uzj+o.pw@kziczvh.com",
        "r.cyo.g+d.h+b.ja@tgsg.z.com",
        "fg.r.u.uzj+o.f.d@kziczvh.com",
        "r.cyo.g+ng.r.iq@tgsg.z.com",
        "fg.r.u.uzj+lp.k@kziczvh.com",
        "r.cyo.g+n.h.e+n.g@tgsg.z.com",
        "fg.r.u.uzj+k+p.j@kziczvh.com",
        "fg.r.u.uzj+w.y+b@kziczvh.com",
        "r.cyo.g+x+d.c+f.t@tgsg.z.com",
        "r.cyo.g+x+t.y.l.i@tgsg.z.com",
        "r.cyo.g+brxxi@tgsg.z.com",
    ];

console.dir(numUniqueEmails(data));

